<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
	<script>var ctx="${ctx}";</script>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <title>小贷客服管理平台</title>
	    <meta name="keywords" content="体验,友好,高级管理台,易用,高性能,高扩展性,bootstrap框架,响应式后台">
	    <meta name="description" content="这是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
	    <meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
		<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT"> 
	    <!--[if lt IE 8]>
	    <meta http-equiv="refresh" content="0;ie.html" />
	    <![endif]-->
	    <link rel="shortcut icon" href="favicon.ico"> 
		<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/footable/footable.core.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/plugins/laypage/laypage.css?v=${static_version}"  rel="stylesheet">
		<link href="${ctx}/static/css/plugins/chosen/chosen.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/animate.min.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/layer/laydate/laydate.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/style.min.css?v=4.0.0" rel="stylesheet">
	    
	</head>
	<body class="gray-bg">
    	<div class="ibox float-e-margins">
    		<div class="ibox-content">
                <form class="form-group" id="sysDict_table_form">	
                    <input type="hidden" name="orderBy" value="group_type,type,value">
                	<div class="row">
                        <div class="col-md-2 col-sm-2"><input name="keyword" type="text" placeholder="请输入关键字" class="form-control" /></div>
						<div class="col-md-1 col-sm-2">
							<button id="sysDict_table_search" type="button" class="btn btn-outline btn-block btn-primary">查询</button>
						</div>
					    <div class="col-md-1 col-sm-2 pull-right ">
							<a  onclick="clickInsertGet()" class="btn btn-block btn-outline btn-primary">添加</a>
					    </div>
                    </div>
                </form>
				<table id="sysDict_table" data-action="${ctx}/dict/find" data-datatable="true"  class="footable table table-stripped toggle-arrow-tiny">
				  	<thead>
					  	<tr>
							<th  data-sort-ignore="true" data-title ="groupType" >组类型</th>
							<th  data-sort-ignore="true" data-title ="type" >类型</th>
							<th  data-sort-ignore="true" data-title ="lable" >名称</th>
							<th  data-sort-ignore="true" data-title ="value" >值</th>
							<th  data-sort-ignore="true" data-title =valueType data-type="enum" data-opt='{"1":"单选","2":"多选","3":"输入","4":"省市区三级联动"}'>值类型</th>
							<th  data-sort-ignore="true" data-title ="hasDefault" data-type="enum" data-opt='{"1":"默认"}'>默认</th>
							<th  data-sort-ignore="true" data-title ="parentLable" >所属节点名称</th>
							<th  data-sort-ignore="true" data-title ="parentType" >所属节点类型</th>
							<th  data-sort-ignore="true" data-title ="status" data-type="enum" data-opt='{"1":"启用","2":"禁用"}'>状态</th>
							<th  data-sort-ignore="true" data-title ="desc" >描述</th>
						  	<th  data-sort-ignore="true" data-crud="true" data-title='{"uid":"id"}' data-hide="phone">操作
			      			  <div style="display: none;" class="center hidden-phone">
			      			  	<button onclick="clickUpdateGet(this)"  data-id=":uid" type="button" style="margin-top:3px" class="btn btn-primary btn-xs">更新</button>
			      			  	<button data-type='change' data-toge="status"  data-callback="changeStatusCallback" data-id=":uid" style="margin-left:3px;margin-top:3px" type="button" class="btn btn-primary btn-xs">启用/禁用</button>
							  	<button onclick="del(this)"  data-id=":uid" type="button" style="margin-left:3px;margin-top:3px"  class="btn btn-primary btn-xs">删除</button>
							  	<button onclick="add(this)"  data-id=":uid" type="button" style="margin-left:3px;margin-top:3px"  class="btn btn-primary btn-xs">添加</button>
							  </div> 
		      		      	</th>
					  	</tr>
				  	</thead>
				  	<tbody>
				  	</tbody>
			  	</table>
			  	<div class="row">
			  		<div class="col-md-4 col-xs-4 col-sm-4 col-lg-4"class="pull-left" id="page_left_text"></div>
			  		<div class="col-md-8"  id="page_text"></div>
			  	</div>
			</div>
		</div>
		
	<script src="${ctx}/static/js/jquery.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/footable/footable.all.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/chosen/chosen.jquery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/laydate/laydate.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/plugins/laypage/laypage.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/switchery/switchery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/eModal.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/cookie.js?v=?v=${static_version}""></script>
	<script src="${ctx}/static/common/custom-datatable.js?v=${static_version}"></script>
	<script src="${ctx}/static/common/common.js?v=${static_version}"></script>
	
	<script>
	
		var changeStatusCallback=function(cData,cLable,row){
			if(row["status"]==2){
				return '<button onclick="clickChangeStatus(this,1)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-success btn-xs"><i class="fa fa-unlock-alt"></i>&nbsp;启用</button>';
			}else{
				return '<button onclick="clickChangeStatus(this,2)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-success btn-xs"><i class="fa fa-unlock-alt"></i>&nbsp;禁用</button>';
			}
		}
		
		//删除
		function del(me){
			$.confirm({
			    text:"确定删除该数据？",
			    confirmButton: "确定",
			    cancelButton: "取消",
			    confirm: function() {
			    	$.ajax({  
			    		url:'${ctx}/dict/delete',  
	   					data:{
	   						id:$(me).data("id")
	   					},   
						type: 'POST',
		 					dataType:'json',  
		 					success:function(response){
		 						if(response.code==0){
		 							eModal.close();
		 							$("#sysDict_table_search").click();
		 						}else{
		 						    $.confirm({cancelButton: "关   闭",title: '提示',text:"删除字典状态错误!"});
		 						}
		 					}  
		 			    });  
			    },
			    cancel: function() {
			        return true;
			    }
			});
		}
		
		var clickChangeStatus=function(me,status){
			 var text="确定禁用该字典?";
			 if(status===1){
				 text="确定启用该字典?";
			 }else if(status===2){
				 text="确定禁用该字典?";
			 }
			 $.confirm({
			    text:text,
			    confirmButton: "确定",
			    cancelButton: "取消",
			    confirm: function() {
			    	$.ajax({  
			    		url:'${ctx}/dict/update',  
	   					data:{
	   						id:$(me).data("id"),
	   						status:status
	   					},   
						type: 'POST',
		 					dataType:'json',  
		 					success:function(response){
		 						if(response.code==0){
		 							eModal.close();
		 							$("#sysDict_table_search").click();
		 						}else{
		 						    $.confirm({cancelButton: "关   闭",title: '提示',text:"改变字典状态错误!"});
		 						}
		 					}  
		 			    });  
			    },
			    cancel: function() {
			        return true;
			    }
			});
		}
	
		$(document).ready(function() {
			init_page_datatable();
		});
		
		var clickInsertGet=function(){
			eModal.ajax({
	   	        url: "${ctx}/dict/insertGet",
	   	        title:'添加字典',
	   	        loading:true,
	   	        size: eModal.size.xl,
	   	        subtitle: '',
	   	        buttons: [
	   	            {text: '保存', style: 'info',   close: false, click:function(){
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/dict/add',  
	   	 					data:{
								parentId:$("#parentId").val(),							
								lable:$("#lable").val(),							
								sort:$("#sort").val(),	
								valueType:$("#valueType").val(),
								groupType:$("#groupType").val(),
								hasDefault:$("#hasDefault").is(":checked")?"1":"2",
								type:$("#type").val(),							
								value:$("#value").val(),							
								status:$("#status").val(),							
								desc:$("#desc").val()							
							},   
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#sysDict_table_search").click();
	   	 						}else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示',text: (me).data("title")+"错误!"||"保存数据错误!"});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
		}
		
		var add=function(me){
			eModal.ajax({
	   	        url: "${ctx}/dict/updateGet?id="+$(me).data("id"),
	   	        title:'修改字典',
	   	        loading:true,
	   	     	size: eModal.size.xl,
	   	        subtitle: '',
	   	        buttons: [
	   	            {text: '保存', style: 'info',   close: false, click:function(){
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/dict/add',  
	   	 					data:{
								parentId:$("#parentId").val(),							
								lable:$("#lable").val(),							
								sort:$("#sort").val(),	
								valueType:$("#valueType").val(),
								groupType:$("#groupType").val(),
								hasDefault:$("#hasDefault").is(":checked")?"1":"2",
								type:$("#type").val(),							
								value:$("#value").val(),							
								status:$("#status").val(),							
								desc:$("#desc").val()							
							},   
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#sysDict_table_search").click();
	   	 						}else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示',text: (me).data("title")+"错误!"||"保存数据错误!"});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
		}
		
		var clickUpdateGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/dict/updateGet?id="+$(me).data("id"),
	   	        title:'修改字典',
	   	        loading:true,
	   	     	size: eModal.size.xl,
	   	        subtitle: '',
	   	        buttons: [
	   	            {text: '保存', style: 'info',   close: false, click:function(){
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/dict/update',  
	   	 					data:{
								parentId:$("#parentId").val(),							
								lable:$("#lable").val(),							
								sort:$("#sort").val(),	
								valueType:$("#valueType").val(),
								groupType:$("#groupType").val(),
								hasDefault:$("#hasDefault").is(":checked")?"1":"2",
								type:$("#type").val(),							
								value:$("#value").val(),							
								status:$("#status").val(),							
								desc:$("#desc").val(),							
								id:$("#id").val()
							},   
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#sysDict_table_search").click();
	   	 						}else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示',text: (me).data("title")+"错误!"||"保存数据错误!"});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
		}
		
		$(function(){
		
			jQuery.searchFormInit();
		    
		});
	</script>
	
	</body>
</html>